cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

#
# Make a version file containing the current version from git.
#
set (VERSION_MAJOR 9)
set (VERSION_MINOR 3)
set (VERSION_PATCH 0)
include(GetOcsswVersion)

#####version 3 of Atrem - no fortran libraries, just C code
#set (ATREM_C_CODE get_atrem_corl1v3.c)
#set (ATREM_F_CODE )
#####version 2 of Atrem - mix with fortran libraries and C code
#set (ATREM_C_CODE get_atrem_corl1v2.c)
#set (ATREM_F_CODE atrem_app_refl_plus_gas_removal_l2v2.f90 atrem_bndprms.f atrem_tpvmr_init.f)
#####version 1 of Atrem - need fortran libraries and code
set (ATREM_C_CODE get_atrem_corl1.c)
set (ATREM_F_CODE atrem_app_refl_plus_gas_removal_l2.f90 atrem_bndprms.f atrem_tpvmr_init.f)

find_package(LibL2 REQUIRED)
include_directories(${LibL2_INCLUDE_DIRS})
set(LIBS ${LibL2_LIBRARIES})

find_package(LibNav REQUIRED)
include_directories(${LibNav_INCLUDE_DIRS})
list(APPEND LIBS ${LibNav_LIBRARIES})

find_package(LibBin++ REQUIRED)
include_directories(${LibBin++_INCLUDE_DIRS})

find_package(LibOsmi REQUIRED)
include_directories(${LibOsmi_INCLUDE_DIRS})
list(APPEND LIBS ${LibOsmi_LIBRARIES})

find_package(LibBilio REQUIRED)
include_directories(${LibBilio_INCLUDE_DIRS})
list(APPEND LIBS ${LibBilio_LIBRARIES})

find_package(Levmar REQUIRED)
include_directories(${Levmar_INCLUDE_DIRS})
list(APPEND LIBS ${Levmar_LIBRARIES})
  
find_package(LAPACK REQUIRED)
include_directories(${LAPACK_INCLUDE_DIRS})
list(APPEND LIBS ${LAPACK_LIBRARIES})

find_package(GeoTIFF REQUIRED)
include_directories(${GeoTIFF_INCLUDE_DIRS})
list(APPEND LIBS ${GeoTIFF_LIBRARIES})

find_package(PugiXML REQUIRED)
include_directories(${PUGIXML_INCLUDE_DIRS})
list(APPEND LIBS ${PUGIXML_LIBRARIES})

find_package(Fann REQUIRED)
include_directories(${Fann_INCLUDE_DIRS})
list(APPEND LIBS ${Fann_LIBRARIES})

find_package(OpenJP2 REQUIRED)
include_directories(${OpenJP2_INCLUDE_DIRS})
list(APPEND LIBS ${OpenJP2_LIBRARIES})

if (BUILD_VIIRS_L1)
    find_package(LibViirsCal REQUIRED)
    include_directories(${LibViirsCal_INCLUDE_DIRS})
    list(APPEND LIBS ${LibViirsCal_LIBRARIES})
    set (VIIRS_L1_SRCS calibrate_viirs.c l1b_viirs_nc.c l1_viirs_nc.c)
else (BUILD_VIIRS_L1)
    set (VIIRS_L1_SRCS calibrate_viirs.c l1b_viirs_nc.c l1_viirs_nc_stub.c)
endif (BUILD_VIIRS_L1)

find_package(NetCDF REQUIRED COMPONENTS CXX F77)
include_directories(${NETCDF_INCLUDE_DIRS})
list(APPEND LIBS ${NETCDF_LIBRARIES})

find_package(PNG REQUIRED)
include_directories(${PNG_INCLUDE_DIRS})


if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
    find_package(X11 REQUIRED)
    include_directories(${X11_INCLUDE_DIR})
    list(APPEND LIBS ${X11_LIBRARIES})
endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

add_executable(l2gen
  main_l2gen.c
  l1subpix.c
  get_l2prod_index.c
  msl12_input.c
  filter.c
  getl1rec.c
  loadl1.c
  xcal.c
  cpl1rec.c
  l1_io.c
  scene_meta.c
  target_io.c
  l1_hdf_generic_read.c
  l1_nc_generic_read.c
  l1_generic_write.c
  l1_mos_hdf.c
  l1_octs_hdf.c
  l1_czcs_hdf.c
  ll2vec.c
  l1_hmodis_hdf.c
  ${VIIRS_L1_SRCS}
  l1_xcal_hdf.c
  etbpsub.f
  ftrim.c
  hmf8.f
  lenstr.f
  raygetpol.f
  simpsn.f
  airmass_avhrr.f
  avhrrsub5h.f
  l1_aci_hdf.c
  l1_meris_N1.c
  smile.c
  l1_meris_CC.c
  l1_ocia.c
  l1_aviris.c
  l1_aviris_nc.c
  l1_olci.c
  l1_prism.c
  l1_viirs_h5.c
  l1_hico_h5.c
  l1_goci.c
  l1_sgli.c
  geom_per_band.c
  viirs_utls.c
  bioOptBandShift.c
  prodgen.c
  prodlist.c
  l2_generic.c
  l1a_seawifs.c
  l1a_osmi.c
  l1_ocm_hdf.c
  l1_ocm2_hdf.c
  l1_ocmdb_hdf.c
  l1_oli.c
  l1_l5tm.c
  l1_l7etm.c
  l1c_msi.cpp
  intpos.f
  l12_seawifs.c
  getformat.c
  getformatXML.cpp
  alloc_l1.c
  alloc_l2.c
  alloc_target.c
  alloc_vcal.c
  convl12.c
  convl21.c
  atmocor1.c
  atmocor1_land.c
  whitecaps.c
  rayleigh.c
  polcor.c
  setanc.c
  setflags.c
  cloud_flag.c
  get_chl.c
  get_habs.c
  get_es.c
  get_Kd.c
  get_ndvi.c
  get_smoke.c
  get_depth.c
  get_poc.c
  get_par.c
  get_toa_refl.c
  get_tricho.c
  get_npp.c
  photic_depth.c
  cdom_morel.c
  calc_par.c
  cdom_mannino.c
  par_utils.c
  ipar.c
  fluorescence.c
  water_vapor.c
  airmass.c
  aerosol.c
  atmocor2.c
  glint.c
  b128_msk_get.c
  b128_wd_bit.c
  b128_box_num.c
  read_mask.c
  getglint.f
  fresnel.c
  get_rhown_nir.c
  mumm.c
  nlw_outband.c
  brdf.c
  filehandle_init.c
  get_dem_height.c
  get_nc_height.c
  get_height.c
  get_rhos.c
  calcite.c
  ice_mask.c
  get_ice_frac.c
  smi_climatology.c
  bin_climatology.c
  aer_io.c
  alloc_aer.c
  amoeba.c
  gsm.c
  giop.c
  mgiop.c
  carder.c
  las_iop.c
  pml.c
  get_pml.c
  pml_iop_calculate.c
  pml_iop_config.c
  pml_iop_tables.c
  qaa.c
  get_qaa.c
  flags_iop.c
  niwa_iop.c
  get_niwa_iop.c
  aph.c
  water.c
  get_f0.c
  windex.c
  brightness.c
  sst.c
  sstref.c
  sssref.c
  soa_sma.c
  atmcor_soa.f
  soa_sma_utils.f
  gas_trans.c
  vcal.c
  myprod.c
  dtran_brdf.f
  turbid.c
  init_l2.c
  init_l1.c
  h5io.c
  convert_band.c
  fuzzy_func_v3.c
  gammln.c
  gcf.c
  gser.c
  nrutil.c
  sprsax.c
  sprsin.c
  covariance_inversion.c
  lubksb.c
  ludcmp.c
  owt.c
  get_owmc.c
  lonlat2pixline.c
  seawater.c
  seawater_get.c
  viirs_pxcvt.c
  virtual_constellation.c
  bioOptBandShift.c
  get_bsi.c
  swim.c
  elev.c
  read_l3bin.cpp
  anc_acq.c
  met_cvt.c
  ncio.c
  get_pft_hirata.c  
  get_pft_uitz.c
  get_mld.c
  get_zno3.c
  ${ATREM_C_CODE}
  rdatreminfo.c
  ${ATREM_F_CODE}
  numerical.c
  raman.c
  get_psd_ksm.c
)

add_executable(l3gen
  main_l3gen.cpp
  l1subpix.c
  get_l2prod_index.c
  msl12_input.c
  filter.c
  getl1rec.c
  loadl1.c
  xcal.c
  cpl1rec.c
  l1_io.c
  scene_meta.c
  target_io.c
  l1_hdf_generic_read.c
  l1_nc_generic_read.c
  l1_generic_write.c
  l1_mos_hdf.c
  l1_octs_hdf.c
  l1_czcs_hdf.c
  ll2vec.c
  l1_hmodis_hdf.c
  ${VIIRS_L1_SRCS}
  l1_xcal_hdf.c
  etbpsub.f
  ftrim.c
  hmf8.f
  lenstr.f
  raygetpol.f
  simpsn.f
  airmass_avhrr.f
  avhrrsub5h.f
  l1_aci_hdf.c
  l1_meris_N1.c
  smile.c
  l1_meris_CC.c
  l1_ocia.c
  l1_aviris.c
  l1_aviris_nc.c
  l1_olci.c
  l1_prism.c
  l1_viirs_h5.c
  l1_hico_h5.c
  l1_goci.c
  l1_sgli.c
  geom_per_band.c
  viirs_utls.c
  bioOptBandShift.c
  prodgen.c
  prodlist.c
  l2_generic.c
  l1a_seawifs.c
  l1a_osmi.c
  l1_ocm_hdf.c
  l1_ocm2_hdf.c
  l1_ocmdb_hdf.c
  l1_oli.c
  l1_l5tm.c
  l1_l7etm.c
  l1c_msi.cpp
  intpos.f
  l12_seawifs.c
  getformat.c
  getformatXML.cpp
  alloc_l1.c
  alloc_l2.c
  alloc_target.c
  alloc_vcal.c
  convl12.c
  convl21.c
  atmocor1.c
  atmocor1_land.c
  whitecaps.c
  rayleigh.c
  polcor.c
  setanc.c
  setflags.c
  cloud_flag.c
  get_chl.c
  get_habs.c
  get_es.c
  get_Kd.c
  get_ndvi.c
  get_smoke.c
  get_depth.c
  get_poc.c
  get_par.c
  get_toa_refl.c
  get_tricho.c
  get_npp.c
  photic_depth.c
  cdom_morel.c
  calc_par.c
  cdom_mannino.c
  par_utils.c
  ipar.c
  fluorescence.c
  water_vapor.c
  airmass.c
  aerosol.c
  atmocor2.c
  glint.c
  b128_msk_get.c
  b128_wd_bit.c
  b128_box_num.c
  read_mask.c
  getglint.f
  fresnel.c
  get_rhown_nir.c
  mumm.c
  nlw_outband.c
  brdf.c
  filehandle_init.c
  get_dem_height.c
  get_nc_height.c
  get_height.c
  get_rhos.c
  calcite.c
  ice_mask.c
  get_ice_frac.c
  smi_climatology.c
  bin_climatology.c
  aer_io.c
  alloc_aer.c
  amoeba.c
  gsm.c
  giop.c
  mgiop.c
  carder.c
  las_iop.c
  pml.c
  get_pml.c
  pml_iop_calculate.c
  pml_iop_config.c
  pml_iop_tables.c
  qaa.c
  get_qaa.c
  niwa_iop.c
  get_niwa_iop.c
  flags_iop.c
  aph.c
  water.c
  get_f0.c
  windex.c
  brightness.c
  sst.c
  sstref.c
  sssref.c
  soa_sma.c
  atmcor_soa.f
  soa_sma_utils.f
  gas_trans.c
  vcal.c
  myprod.c
  dtran_brdf.f
  turbid.c
  init_l2.c
  init_l1.c
  h5io.c
  convert_band.c
  fuzzy_func_v3.c
  gammln.c
  gcf.c
  gser.c
  nrutil.c
  sprsax.c
  sprsin.c
  covariance_inversion.c
  lubksb.c
  ludcmp.c
  owt.c
  get_owmc.c
  seawater.c
  seawater_get.c
  viirs_pxcvt.c
  virtual_constellation.c
  bioOptBandShift.c  
  get_bsi.c
  swim.c
  elev.c
  read_l3bin.cpp
  anc_acq.c
  met_cvt.c
  ncio.c
  get_pft_hirata.c 
  get_pft_uitz.c
  get_mld.c
  get_zno3.c
  ${ATREM_C_CODE}
  rdatreminfo.c
  ${ATREM_F_CODE}
  numerical.c
  raman.c
  get_psd_ksm.c
)

add_executable(l3gen64
  main_l3gen64.cpp
  l1subpix.c
  get_l2prod_index.c
  msl12_input.c
  filter.c
  getl1rec.c
  loadl1.c
  xcal.c
  cpl1rec.c
  l1_io.c
  scene_meta.c
  target_io.c
  l1_hdf_generic_read.c
  l1_nc_generic_read.c
  l1_generic_write.c
  l1_mos_hdf.c
  l1_octs_hdf.c
  l1_czcs_hdf.c
  ll2vec.c
  l1_hmodis_hdf.c
  ${VIIRS_L1_SRCS}
  l1_xcal_hdf.c
  etbpsub.f
  ftrim.c
  hmf8.f
  lenstr.f
  raygetpol.f
  simpsn.f
  airmass_avhrr.f
  avhrrsub5h.f
  l1_aci_hdf.c
  l1_meris_N1.c
  smile.c
  l1_meris_CC.c
  l1_ocia.c
  l1_aviris.c
  l1_aviris_nc.c
  l1_olci.c
  l1_prism.c
  l1_viirs_h5.c
  l1_hico_h5.c
  l1_goci.c
  l1_sgli.c
  geom_per_band.c
  viirs_utls.c
  bioOptBandShift.c
  prodgen.c
  prodlist.c
  l2_generic.c
  l1a_seawifs.c
  l1a_osmi.c
  l1_ocm_hdf.c
  l1_ocm2_hdf.c
  l1_ocmdb_hdf.c
  l1_oli.c
  l1_l5tm.c
  l1_l7etm.c
  l1c_msi.cpp
  intpos.f
  l12_seawifs.c
  getformat.c
  getformatXML.cpp
  alloc_l1.c
  alloc_l2.c
  alloc_target.c
  alloc_vcal.c
  convl12.c
  convl21.c
  atmocor1.c
  atmocor1_land.c
  whitecaps.c
  rayleigh.c
  polcor.c
  setanc.c
  setflags.c
  cloud_flag.c
  get_chl.c
  get_habs.c
  get_es.c
  get_Kd.c
  get_ndvi.c
  get_smoke.c
  get_depth.c
  get_poc.c
  get_par.c
  get_toa_refl.c
  get_tricho.c
  get_npp.c
  photic_depth.c
  cdom_morel.c
  calc_par.c
  cdom_mannino.c
  par_utils.c
  ipar.c
  fluorescence.c
  water_vapor.c
  airmass.c
  aerosol.c
  atmocor2.c
  glint.c
  b128_msk_get.c
  b128_wd_bit.c
  b128_box_num.c
  read_mask.c
  getglint.f
  fresnel.c
  get_rhown_nir.c
  mumm.c
  nlw_outband.c
  brdf.c
  filehandle_init.c
  get_dem_height.c
  get_nc_height.c
  get_height.c
  get_rhos.c
  calcite.c
  ice_mask.c
  get_ice_frac.c
  smi_climatology.c
  bin_climatology.c
  aer_io.c
  alloc_aer.c
  amoeba.c
  gsm.c
  giop.c
  mgiop.c
  carder.c
  las_iop.c
  pml.c
  get_pml.c
  pml_iop_calculate.c
  pml_iop_config.c
  pml_iop_tables.c
  qaa.c
  get_qaa.c
  niwa_iop.c
  get_niwa_iop.c
  flags_iop.c
  aph.c
  water.c
  get_f0.c
  windex.c
  brightness.c
  sst.c
  sstref.c
  sssref.c
  soa_sma.c
  atmcor_soa.f
  soa_sma_utils.f
  gas_trans.c
  vcal.c
  myprod.c
  dtran_brdf.f
  turbid.c
  init_l2.c
  init_l1.c
  h5io.c
  convert_band.c
  fuzzy_func_v3.c
  gammln.c
  gcf.c
  gser.c
  nrutil.c
  sprsax.c
  sprsin.c
  covariance_inversion.c
  lubksb.c
  ludcmp.c
  owt.c
  get_owmc.c
  seawater.c
  seawater_get.c
  viirs_pxcvt.c
  virtual_constellation.c
  bioOptBandShift.c  
  get_bsi.c
  swim.c
  elev.c
  read_l3bin.cpp
  anc_acq.c
  met_cvt.c
  ncio.c
  get_pft_hirata.c 
  get_pft_uitz.c
  get_mld.c
  get_zno3.c
  ${ATREM_C_CODE}
  rdatreminfo.c
  ${ATREM_F_CODE}
  numerical.c
  raman.c
  get_psd_ksm.c
)

add_executable(l1bgen_generic
  main_l1bgen.c
  msl12_input.c
  filter.c
  get_f0.c
  l1_generic_write.c
  l1_hdf_generic_read.c
  l1_nc_generic_read.c
  l1_mos_hdf.c
  l1_octs_hdf.c
  l1_czcs_hdf.c
  ll2vec.c
  l1_hmodis_hdf.c
  ${VIIRS_L1_SRCS}
  etbpsub.f
  ftrim.c
  hmf8.f
  lenstr.f
  raygetpol.f
  simpsn.f
  airmass_avhrr.f
  avhrrsub5h.f
  l1_xcal_hdf.c
  l1_aci_hdf.c
  l1_meris_N1.c
  smile.c
  l1_meris_CC.c
  l1_ocia.c
  l1_aviris.c
  l1_aviris_nc.c
  l1_olci.c
  l1_prism.c
  l1_viirs_h5.c
  l1_hico_h5.c
  l1_goci.c
  l1_sgli.c
  geom_per_band.c
  viirs_utls.c
  l1a_seawifs.c
  l1a_osmi.c
  l1_ocm_hdf.c
  l1_ocm2_hdf.c
  l1_ocmdb_hdf.c
  l1_oli.c
  l1_l5tm.c
  l1_l7etm.c
  l1c_msi.cpp
  intpos.f
  l12_seawifs.c
  getformat.c
  getformatXML.cpp
  alloc_l1.c
  l1subpix.c
  filehandle_init.c
  l1_io.c
  scene_meta.c
  smi_climatology.c
  setflags.c
  cloud_flag.c
  water.c
  brightness.c
  windex.c
  getglint.f
  init_l1.c
  init_l2.c
  h5io.c
  viirs_pxcvt.c
  ${ATREM_C_CODE}
  rdatreminfo.c
  ${ATREM_F_CODE}
  numerical.c
  get_habs.c
  xcal.c
  )

add_executable(l1brsgen
  main_l1brsgen.c
  l1_imgscale.c
  msl12_input.c
  filter.c
  gas_trans.c
  loadl1.c
  seawater.c
  seawater_get.c
  xcal.c
  get_f0.c
  setanc.c
  atmocor1.c
  atmocor1_land.c
  whitecaps.c
  rayleigh.c
  polcor.c
  water_vapor.c
  b128_msk_get.c
  b128_wd_bit.c
  b128_box_num.c
  read_mask.c
  l1_hdf_generic_read.c
  l1_nc_generic_read.c
  l1_generic_write.c
  l1_mos_hdf.c
  l1_octs_hdf.c
  l1_czcs_hdf.c
  ll2vec.c
  l1a_seawifs.c
  l1a_osmi.c
  l1_ocm_hdf.c
  l1_ocm2_hdf.c
  l1_ocmdb_hdf.c
  l1_hmodis_hdf.c
  ${VIIRS_L1_SRCS}
  l1_xcal_hdf.c
  etbpsub.f
  ftrim.c
  hmf8.f
  lenstr.f
  raygetpol.f
  simpsn.f
  airmass_avhrr.f
  avhrrsub5h.f
  l1_aci_hdf.c
  l1_meris_N1.c
  smile.c
  l1_meris_CC.c
  l1_ocia.c
  l1_aviris.c
  l1_aviris_nc.c
  l1_olci.c
  l1_prism.c
  l1_viirs_h5.c
  l1_hico_h5.c
  l1_goci.c
  l1_sgli.c
  geom_per_band.c
  l1_oli.c
  l1_l5tm.c
  l1_l7etm.c
  l1c_msi.cpp
  viirs_utls.c
  h5io.c
  intpos.f
  getformat.c
  getformatXML.cpp
  alloc_l1.c
  l1subpix.c
  filehandle_init.c
  get_dem_height.c
  get_nc_height.c
  get_height.c
  get_rhos.c
  ice_mask.c
  smi_climatology.c
  l1_io.c
  scene_meta.c
  brightness.c
  sstref.c
  sssref.c
  setflags.c
  cloud_flag.c
  water.c
  windex.c
  getglint.f
  init_l1.c
  viirs_pxcvt.c
  elev.c
  anc_acq.c
  met_cvt.c
  ncio.c
  ${ATREM_C_CODE}
  rdatreminfo.c
  ${ATREM_F_CODE}
  numerical.c
  get_habs.c
  )

add_executable(l1mapgen
  main_l1mapgen.c
  l1_imgscale.c
  msl12_input.c
  filter.c
  gas_trans.c
  loadl1.c
  seawater.c
  seawater_get.c
  xcal.c
  get_f0.c
  setanc.c
  atmocor1.c
  atmocor1_land.c
  whitecaps.c
  rayleigh.c
  polcor.c
  water_vapor.c
  b128_msk_get.c
  b128_wd_bit.c
  b128_box_num.c
  read_mask.c
  l1_hdf_generic_read.c
  l1_nc_generic_read.c
  l1_generic_write.c
  l1_mos_hdf.c
  l1_octs_hdf.c
  l1_czcs_hdf.c
  ll2vec.c
  l1a_seawifs.c
  l1a_osmi.c
  l1_ocm_hdf.c
  l1_ocm2_hdf.c
  l1_ocmdb_hdf.c
  l1_hmodis_hdf.c
  ${VIIRS_L1_SRCS}
  etbpsub.f
  ftrim.c
  hmf8.f
  lenstr.f
  raygetpol.f
  simpsn.f
  airmass_avhrr.f
  avhrrsub5h.f
  l1_xcal_hdf.c
  l1_aci_hdf.c
  l1_meris_N1.c
  smile.c
  l1_meris_CC.c
  l1_ocia.c
  l1_aviris.c
  l1_aviris_nc.c
  l1_olci.c
  l1_prism.c
  l1_viirs_h5.c
  l1_hico_h5.c
  l1_goci.c
  l1_sgli.c
  geom_per_band.c
  l1_oli.c
  l1_l5tm.c
  l1_l7etm.c
  l1c_msi.cpp
  viirs_utls.c
  h5io.c
  intpos.f
  getformat.c
  getformatXML.cpp
  alloc_l1.c
  l1subpix.c
  filehandle_init.c
  get_dem_height.c
  get_nc_height.c
  get_height.c
  get_rhos.c
  ice_mask.c
  smi_climatology.c
  l1_io.c
  scene_meta.c
  brightness.c
  sstref.c
  sssref.c
  setflags.c
  cloud_flag.c
  water.c
  windex.c
  getglint.f
  mipolyutil.c
  init_l1.c
  viirs_pxcvt.c
  elev.c
  anc_acq.c
  met_cvt.c
  ncio.c
  ${ATREM_C_CODE}
  rdatreminfo.c
  ${ATREM_F_CODE}
  numerical.c
  get_habs.c
  )

add_executable(l1info
  main_l1info.c
  msl12_input.c
  filter.c
  get_f0.c
  l1_hdf_generic_read.c
  l1_nc_generic_read.c
  l1_generic_write.c
  l1_mos_hdf.c
  l1_octs_hdf.c
  l1_czcs_hdf.c
  ll2vec.c
  l1a_seawifs.c
  l1a_osmi.c
  l1_ocm_hdf.c
  l1_ocm2_hdf.c
  l1_ocmdb_hdf.c
  l1_hmodis_hdf.c
  ${VIIRS_L1_SRCS}
  etbpsub.f
  ftrim.c
  hmf8.f
  lenstr.f
  raygetpol.f
  simpsn.f
  airmass_avhrr.f
  avhrrsub5h.f
  l1_xcal_hdf.c
  l1_aci_hdf.c
  l1_meris_N1.c
  smile.c
  l1_meris_CC.c
  l1_ocia.c
  l1_aviris.c
  l1_aviris_nc.c
  l1_olci.c
  l1_prism.c
  l1_viirs_h5.c
  l1_hico_h5.c
  l1_goci.c
  l1_sgli.c
  geom_per_band.c
  l1_oli.c
  l1_l5tm.c
  l1_l7etm.c
  l1c_msi.cpp
  viirs_utls.c
  h5io.c
  intpos.f
  getformat.c
  getformatXML.cpp
  alloc_l1.c
  l1subpix.c
  filehandle_init.c
  l1_io.c
  scene_meta.c
  smi_climatology.c
  brightness.c
  setflags.c
  cloud_flag.c
  water.c
  windex.c
  getglint.f
  init_l1.c
  viirs_pxcvt.c
  elev.c
  get_habs.c
  xcal.c
  )

add_executable(lonlat2pixline
  main_lonlat2pixline.c
  msl12_input.c
  filter.c
  get_f0.c
  l1_generic_write.c
  l1_hdf_generic_read.c
  l1_nc_generic_read.c
  l1_mos_hdf.c
  l1_octs_hdf.c
  l1_czcs_hdf.c
  ll2vec.c
  l1a_seawifs.c
  l1a_osmi.c
  l1_ocm_hdf.c
  l1_ocm2_hdf.c
  l1_ocmdb_hdf.c
  l1_hmodis_hdf.c
  ${VIIRS_L1_SRCS}
  l1_xcal_hdf.c
  etbpsub.f
  ftrim.c
  hmf8.f
  lenstr.f
  raygetpol.f
  simpsn.f
  airmass_avhrr.f
  avhrrsub5h.f
  l1_aci_hdf.c
  l1_meris_N1.c
  smile.c
  l1_meris_CC.c
  l1_ocia.c
  l1_aviris.c
  l1_aviris_nc.c
  l1_olci.c
  l1_prism.c
  l1_viirs_h5.c
  l1_hico_h5.c
  l1_goci.c
  l1_sgli.c
  geom_per_band.c
  l1_oli.c
  l1_l5tm.c
  l1_l7etm.c
  l1c_msi.cpp
  viirs_utls.c
  h5io.c
  intpos.f
  getformat.c
  getformatXML.cpp
  alloc_l1.c
  l1subpix.c
  l1_io.c
  scene_meta.c
  l12_seawifs.c
  filehandle_init.c
  brightness.c
  smi_climatology.c
  setflags.c
  cloud_flag.c
  water.c
  windex.c
  getglint.f
  init_l1.c
  lonlat2pixline.c
  viirs_pxcvt.c
  get_habs.c
  xcal.c
  )

add_executable(vcalmerge
  main_vcalmerge.c
  calfile_utils.c
  msl12_input.c
  l2_generic.c
  filter.c
  gas_trans.c
  loadl1.c
  seawater.c
  seawater_get.c
  xcal.c
  get_f0.c
  setanc.c
  atmocor1.c
  atmocor1_land.c
  whitecaps.c
  rayleigh.c
  polcor.c
  water_vapor.c
  b128_msk_get.c
  b128_wd_bit.c
  b128_box_num.c
  read_mask.c
  fresnel.c
  l1_generic_write.c
  l1_hdf_generic_read.c
  l1_nc_generic_read.c
  l1_mos_hdf.c
  l1_octs_hdf.c
  l1_czcs_hdf.c
  ll2vec.c
  l1a_seawifs.c
  l1a_osmi.c
  l1_ocm_hdf.c
  l1_ocm2_hdf.c
  l1_ocmdb_hdf.c
  l1_hmodis_hdf.c
  ${VIIRS_L1_SRCS}
  l1_xcal_hdf.c
  etbpsub.f
  ftrim.c
  hmf8.f
  lenstr.f
  raygetpol.f
  simpsn.f
  airmass_avhrr.f
  avhrrsub5h.f
  l1_aci_hdf.c
  l1_meris_N1.c
  smile.c
  l1_meris_CC.c
  l1_ocia.c
  l1_aviris.c
  l1_aviris_nc.c
  l1_olci.c
  l1_prism.c
  l1_viirs_h5.c
  l1_hico_h5.c
  l1_goci.c
  l1_sgli.c
  geom_per_band.c
  l1_oli.c
  l1_l5tm.c
  l1_l7etm.c
  l1c_msi.cpp
  viirs_utls.c
  h5io.c
  bioOptBandShift.c
  prodgen.c
  prodlist.c
  intpos.f
  getformat.c
  getformatXML.cpp
  alloc_l1.c
  l1subpix.c
  filehandle_init.c
  get_dem_height.c
  get_nc_height.c
  get_height.c
  get_rhos.c
  ice_mask.c
  smi_climatology.c
  l1_io.c
  scene_meta.c
  brightness.c
  sstref.c
  sssref.c
  setflags.c
  cloud_flag.c
  water.c
  windex.c
  getglint.f
  init_l1.c
  viirs_pxcvt.c
  elev.c
  convl12.c
  convl21.c
  alloc_l2.c
  read9km_mask.c
  getl1rec.c
  alloc_aer.c
  alloc_target.c
  carder.c
  gsm.c
  get_pml.c
  sst.c
  get_l2prod_index.c
  init_l2.c
  get_niwa_iop.c
  las_iop.c
  get_chl.c
  get_habs.c
  get_qaa.c
  giop.c
  mgiop.c
  qaa.c
  get_es.c
  get_Kd.c
  get_ndvi.c
  get_smoke.c
  get_depth.c
  get_poc.c
  get_par.c
  get_toa_refl.c
  get_tricho.c
  get_npp.c
  photic_depth.c
  cdom_morel.c
  get_ice_frac.c
  calc_par.c
  cdom_mannino.c
  par_utils.c
  ipar.c
  fluorescence.c
  calcite.c
  alloc_vcal.c
  vcal.c
  virtual_constellation.c
  bioOptBandShift.c  
  lubksb.c
  ludcmp.c
  covariance_inversion.c
  nrutil.c
  sprsax.c
  sprsin.c
  gammln.c
  gcf.c
  gser.c
  fuzzy_func_v3.c
  owt.c
  get_owmc.c
  get_bsi.c
  get_pft_hirata.c  
  get_pft_uitz.c
  get_mld.c
  get_zno3.c
  lonlat2pixline.c
  atmocor2.c
  brdf.c
  cpl1rec.c
  amoeba.c
  pml_iop_tables.c
  pml.c
  pml_iop_calculate.c
  pml_iop_config.c
  niwa_iop.c
  convert_band.c
  soa_sma.c
  atmcor_soa.f
  soa_sma_utils.f
  aph.c
  flags_iop.c
  dtran_brdf.f
  turbid.c
  glint.c
  mumm.c
  get_rhown_nir.c
  aerosol.c
  nlw_outband.c
  airmass.c
  bin_climatology.c
  anc_acq.c
  met_cvt.c
  ncio.c
  swim.c
  ${ATREM_C_CODE}
  rdatreminfo.c
  ${ATREM_F_CODE}
  raman.c 
  numerical.c
  get_psd_ksm.c


)

add_executable(l2binmatch
  main_l2binmatch.cpp
  l2binmatch_input.cpp
  get_l2prod_index.c
  calfile_utils.c
  elev.c
 )

add_executable(l2binmatch64
  main_l2binmatch64.cpp
  l2binmatch_input.cpp
  get_l2prod_index.c
  calfile_utils.c
  elev.c
 )

add_executable(l1det2det
  main_l1det2det.c
  calfile_utils.c
  msl12_input.c
  l2_generic.c
  filter.c
  gas_trans.c
  loadl1.c
  seawater.c
  seawater_get.c
  xcal.c
  get_f0.c
  setanc.c
  atmocor1.c
  atmocor1_land.c
  whitecaps.c
  rayleigh.c
  polcor.c
  water_vapor.c
  b128_msk_get.c
  b128_wd_bit.c
  b128_box_num.c
  read_mask.c
  fresnel.c
  l1_generic_write.c
  l1_hdf_generic_read.c
  l1_nc_generic_read.c
  l1_mos_hdf.c
  l1_octs_hdf.c
  l1_czcs_hdf.c
  ll2vec.c
  l1a_seawifs.c
  l1a_osmi.c
  l1_ocm_hdf.c
  l1_ocm2_hdf.c
  l1_ocmdb_hdf.c
  l1_hmodis_hdf.c
  ${VIIRS_L1_SRCS}
  l1_xcal_hdf.c
  etbpsub.f
  ftrim.c
  hmf8.f
  lenstr.f
  raygetpol.f
  simpsn.f
  airmass_avhrr.f
  avhrrsub5h.f
  l1_aci_hdf.c
  l1_meris_N1.c
  smile.c
  l1_meris_CC.c
  l1_ocia.c
  l1_aviris.c
  l1_aviris_nc.c
  l1_olci.c
  l1_prism.c
  l1_viirs_h5.c
  l1_hico_h5.c
  l1_goci.c
  l1_sgli.c
  geom_per_band.c
  l1_oli.c
  l1_l5tm.c
  l1_l7etm.c
  l1c_msi.cpp
  viirs_utls.c
  h5io.c
  bioOptBandShift.c
  prodgen.c
  prodlist.c
  intpos.f
  getformat.c
  getformatXML.cpp
  alloc_l1.c
  l1subpix.c
  filehandle_init.c
  get_dem_height.c
  get_nc_height.c
  get_height.c
  get_rhos.c
  ice_mask.c
  smi_climatology.c
  l1_io.c
  scene_meta.c
  brightness.c
  sstref.c
  sssref.c
  setflags.c
  cloud_flag.c
  water.c
  windex.c
  getglint.f
  init_l1.c
  viirs_pxcvt.c
  elev.c
  convl12.c
  convl21.c
  alloc_l2.c
  read9km_mask.c
  getl1rec.c
  alloc_aer.c
  alloc_target.c
  carder.c
  gsm.c
  get_pml.c
  sst.c
  get_l2prod_index.c
  init_l2.c
  get_niwa_iop.c
  las_iop.c
  get_chl.c
  get_habs.c
  get_qaa.c
  giop.c
  mgiop.c
  qaa.c
  get_es.c
  get_Kd.c
  get_ndvi.c
  get_smoke.c
  get_depth.c
  get_poc.c
  get_par.c
  get_toa_refl.c
  get_tricho.c
  get_npp.c
  photic_depth.c
  cdom_morel.c
  get_ice_frac.c
  calc_par.c
  cdom_mannino.c
  par_utils.c
  ipar.c
  fluorescence.c
  calcite.c
  alloc_vcal.c
  vcal.c
  virtual_constellation.c
  bioOptBandShift.c  
  lubksb.c
  ludcmp.c
  covariance_inversion.c
  nrutil.c
  sprsax.c
  sprsin.c
  gammln.c
  gcf.c
  gser.c
  fuzzy_func_v3.c
  owt.c
  get_owmc.c
  get_bsi.c
  get_pft_hirata.c  
  get_pft_uitz.c
  get_mld.c
  get_zno3.c
  lonlat2pixline.c
  atmocor2.c
  brdf.c
  cpl1rec.c
  amoeba.c
  pml_iop_tables.c
  pml.c
  pml_iop_calculate.c
  pml_iop_config.c
  niwa_iop.c
  convert_band.c
  soa_sma.c
  atmcor_soa.f
  soa_sma_utils.f
  aph.c
  flags_iop.c
  dtran_brdf.f
  turbid.c
  glint.c
  mumm.c
  get_rhown_nir.c
  aerosol.c
  nlw_outband.c
  airmass.c
  bin_climatology.c
  anc_acq.c
  met_cvt.c
  ncio.c
  swim.c
  ${ATREM_C_CODE}
  rdatreminfo.c
  ${ATREM_F_CODE}
  numerical.c
  raman.c 
  get_psd_ksm.c
  )

include_directories (
#  ${CMAKE_SOURCE_DIR}/include
  ${CMAKE_SOURCE_DIR}/include/meris
  )

target_link_libraries(l2gen
  ${LibBin++_LIBRARIES}
  anc
  czcs
  meris
  goci
  oli
  bilio
  ${LIBS}
  )

target_link_libraries(l3gen
  ${LibBin++_LIBRARIES}
  anc
  czcs
  osmi
  meris
  goci
  oli
  bilio
  ${LIBS}
  )
  
target_link_libraries(l3gen64
  ${LibBin++_LIBRARIES}
  anc
  czcs
  osmi
  meris
  goci
  oli
  bilio
  ${LIBS}
  )

target_link_libraries(l1bgen_generic
  czcs
  osmi
  meris
  goci
  oli
  bilio
  ${LIBS}
  )

target_link_libraries(l1brsgen
  anc
  czcs
  osmi
  meris
  goci
  oli
  imageutils
  bilio
  ${LIBS}
  )

target_link_libraries(l1mapgen
  anc
  czcs
  osmi
  meris
  goci
  oli
  ${PNG_LIBRARIES}
  bilio
  ${LIBS}
  )

target_link_libraries(l1info
  czcs
  osmi
  meris
  goci
  oli
  bilio
  ${LIBS}
  )

target_link_libraries(lonlat2pixline
  czcs
  osmi
  meris
  goci
  oli
  bilio
  ${LIBS}
  )

target_link_libraries(vcalmerge
  ${LibBin++_LIBRARIES}
  anc
  czcs
  osmi
  meris
  goci
  oli
  bilio
  ${LIBS}
  )

target_link_libraries(l2binmatch
  ${LibBin++_LIBRARIES}
  ${LIBS}
  )
  
target_link_libraries(l2binmatch64
  ${LibBin64++_LIBRARIES}
  ${LIBS}
  )

target_link_libraries(l1det2det
  ${LibBin++_LIBRARIES}
  anc
  czcs
  osmi
  meris
  goci
  oli
  bilio
  ${LIBS}
  )

#set (CMAKE_C_FLAGS_RELEASE "-O1") 
# Use -Wpadded -Wpacked to warn about align-double. Use  '#pragma GCC diagnostic ignored "-Wpadded"' in file if you don't want to see messages
# -malign-double needed for accessing fortran common blocks from C structs

set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -malign-double -mpreferred-stack-boundary=8")
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -malign-double -mpreferred-stack-boundary=8")

install (TARGETS l2gen l3gen l3gen64 l1bgen_generic l1brsgen l1mapgen l1info lonlat2pixline vcalmerge l2binmatch l2binmatch64 l1det2det DESTINATION bin)
